package _83RemoveDuplicatesFromSortedList;

public class CSolution {

  public static void main(String[] args) {
    System.out.println("aa");
    ListNode a0 = new ListNode();
    ListNode a1 = new ListNode();
    ListNode a2 = new ListNode();
    ListNode a3 = new ListNode();
    a0.val = 1;
    a0.next = a1;
    a1.val = 2;
    a1.next = a2;
    a2.val = 3;
    a2.next = a3;
    a3.val = 3;
    CSolution cSolution = new CSolution();
    ListNode listNode = cSolution.solution(a0);
    System.out.println(listNode);
  }

  private ListNode solution(ListNode head) {
    if (head == null || head.next == null) {
      return head;
    }
    ListNode thisOne = head;
    ListNode nextOne = head.next;
    while (thisOne != null && nextOne != null) {
      if (nextOne.val == thisOne.val) {
        nextOne = nextOne.next;
        thisOne.next = nextOne;
      } else {
        thisOne = nextOne;
        nextOne = nextOne.next;
        thisOne.next = nextOne;
      }
    }
    return head;
  }
}
